package com.itheima.controller.admin;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.BusinessReportData;
import com.itheima.pojo.MemberReport;
import com.itheima.pojo.SetmealReport;
import com.itheima.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;


@RestController
@RequestMapping("/report")
@Api(tags = "统计报表相关接口")
@Slf4j
public class ReportController {
    @Autowired
    private ReportService reportService;

    /**
     * 获取会员数量统计数据
     * @return
     */
    @GetMapping("/getMemberReport")
    @ApiOperation("获取会员数量统计数据")
    public Result getMemberReport(){
        log.info("获取会员数量统计数据");
        MemberReport result = reportService.getMemberReport();
        return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS,result);
    }

    /**
     * 获取套餐占比统计数据
     * @return
     */
    @GetMapping("/getSetmealReport")
    @ApiOperation("获取套餐占比统计数据")
    public Result getSetmealReport(){
        log.info("获取套餐占比统计数据");
        SetmealReport result = reportService.getSetmealReport();
        return new Result(true,MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS,result);
    }

    /**
     * 获取运营统计数据
     * @return
     */
    @GetMapping("/getBusinessReportData")
    @ApiOperation("获取运营统计数据")
    public Result getBusinessReportData(){
        log.info("获取运营统计数据");
        BusinessReportData result = reportService.getBusinessReportData();
        return new Result(true,MessageConstant.GET_BUSINESS_REPORT_SUCCESS,result);
    }

    /**
     * 导出运营数据到Excel并提供客户端下载
     * @param response
     */
    @GetMapping("/exportBusinessReport")
    @ApiOperation("导出运营数据到Excel并提供客户端下载")
    public void exportBusinessReport(HttpServletResponse response){
        log.info("导出运营数据到Excel并提供客户端下载");
        reportService.exportBusinessReport(response);
    }
}
